package me.service.impl;

import me.dao.AdminDao;
import me.domain.Admin;
import me.service.AdminService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * service定义方法，供servlet调用
 */
@Service(value = "adminService")
@Scope(value = "prototype")
public class AdminServiceImpl implements AdminService {

    //创建adminDao对象
//    private AdminDao adminDao = new AdminDaoImpl();
    //使用工厂创建adminDao对象
//    private AdminDao adminDao = FactoryDaoImpl.getInstance().createAdminDao();
    //通过工厂类获取adminDao对象，使用多例  如果需要单例需要写在方法内部
//    private AdminDao adminDao = (AdminDaoImpl)Factory.getBeans("adminDao");

    //通过spring容器获取容器对象
//    ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");
    //通过容器获取adminDao对象
//    AdminDao adminDao = ac.getBean("adminDao", AdminDaoImpl.class);

//    @Autowired()
//    @Qualifier(value = "adminDao")
//    private AdminDao adminDao = new AdminDaoImpl();

    @Resource(name = "adminDao")
    private AdminDao adminDao;

    @Override
    public boolean exist(Admin admin) {

        //调用adminDao对象里的查询方法
        return adminDao.queryByAccountAndPassword(admin.getAccount(),admin.getPassword());
    }
}
